#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    timerId=this->startTimer(1000);//开启定时器,单位ms,返回值是该定时器的身份标识
}

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *event)
{
    int value=ui->lcdNumber->intValue();
    if(event->timerId()!=this->timerId) return;//非此定时器不做理会
    if(value<=0)
    {
        this->killTimer(this->timerId);//关闭定时器
        return;
    }
    else
    {
        ui->lcdNumber->display(--value);
    }
}

